/*
 * @Author: hifishroom
 * @Date: 2021-08-17 21:49:15
 * @LastEditTime: 2021-09-02 23:57:05
 * @FilePath: \index\src\store\index.js
 */
import Vue from "vue";
import Vuex from "vuex";

import actions from "./actions";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    rankingList: {
      // 硬地
      unyieldinglyList: { title: "", list: [], img: "" },
      // 说唱
      talkingList: { title: "", list: [], img: "" },
      // 原创
      originalList: { title: "", list: [], img: "" },
      // 最热视频榜
      HotVideoList: { title: "", list: [], img: "" },
      // 飙升榜
      soaringList: { title: "", list: [], img: "" }
    },
    goods: {
      newSong: [],
      newPlate: [],
      album: []
    },
    currentType: "newSong"
  },
  getters: {},
  mutations: {
    //^ 排行榜
    changeRankingList(state, obj) {
      // 硬地
      state.rankingList.unyieldinglyList.title = obj[1].name;
      state.rankingList.unyieldinglyList.list = obj[1].tracks;
      state.rankingList.unyieldinglyList.img = obj[1].coverImgUrl;
      // 说唱
      state.rankingList.talkingList.title = obj[3].name;
      state.rankingList.talkingList.list = obj[3].tracks;
      state.rankingList.unyieldinglyList.img = obj[3].coverImgUrl;
      // 原创
      state.rankingList.originalList.title = obj[2].name;
      state.rankingList.originalList.list = obj[2].tracks;
      state.rankingList.unyieldinglyList.img = obj[2].coverImgUrl;
      // 最热视频榜
      state.rankingList.HotVideoList.title = obj[4].name;
      state.rankingList.HotVideoList.list = obj[4].tracks;
      state.rankingList.unyieldinglyList.img = obj[4].coverImgUrl;
      // 飙升榜
      state.rankingList.soaringList.title = obj[0].name;
      state.rankingList.soaringList.list = obj[0].tracks;
      state.rankingList.unyieldinglyList.img = obj[0].coverImgUrl;
    },

    //^ 新歌
    getHomeNewSong(state, list) {
      //! 先过滤再拆分数组
      let tempres = list.map(item => {
        let rsitem = {};
        rsitem.name = item.name;
        rsitem.picUrl = item.picUrl;
        rsitem.user = item.song.artists[0].name;
        rsitem.intor = item.song.album.company;
        return rsitem;
      });
      state.goods.newSong = [];
      for (let i = 0; i < tempres.length / 3; i++) {
        state.goods.newSong[i] = tempres.slice(3 * i, 3 * (i + 1));
      }
    },

    //^ 新碟
    getHomeNewPlate(state, list) {
      let tempres = list.map(item => {
        let rsitem = {};
        rsitem.name = item.name;
        rsitem.picUrl = item.picUrl;
        rsitem.user = item.artist.name;
        rsitem.intor = item.company;
        return rsitem;
      });

      for (let i = 0; i < tempres.length / 3; i++) {
        state.goods.newPlate[i] = tempres.slice(3 * i, 3 * (i + 1));
      }
    },

    //^ 新专辑
    getHomeAlbum(state, list) {
      let tempres = list.map(item => {
        let rsitem = {};
        rsitem.name = item.name;
        rsitem.picUrl = item.picUrl;
        rsitem.user = item.artist.name;
        rsitem.intor = item.company;
        return rsitem;
      });
      for (let i = 0; i < tempres.length / 3; i++) {
        state.goods.album[i] = tempres.slice(3 * i, 3 * (i + 1));
      }
    }
  },
  actions,
  modules: {}
});
